<template>
  <div class="app-container balance-box">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="6" :md="6" :lg="4">
        <!-- 分类数据 -->
        <Tree
          ref="tree"
          :sortTree="sortTree"
          :isHeight="isHeight"
          :loading="loading"
          :isOperation="isOperation"
          @nodeClick="nodeClick(arguments)"
          :searchName="searchName"
        />
      </el-col>
      <!-- 搜索数据 -->
      <el-col :span="20" :xs="24">
        <el-form
          :inline="true"
          label-width="68px"
          style="margin-bottom: 15px"
          v-hasPermi="['wm:balance:query']"
        >
          <el-form-item label="物料编码">
            <el-input
              v-model="searchForm.searchCode"
              clearable
              size="small"
              style="width: 240px"
            />
          </el-form-item>
          <el-form-item label="物料名称">
            <el-input
              v-model="searchForm.searchName"
              clearable
              size="small"
              style="width: 240px"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              v-hasPermi="['wm:balance:query']"
              type="primary"
              icon="el-icon-search"
              @click="search"
              >搜索
            </el-button>
            <el-button
              v-hasPermi="['wm:balance:query']"
              icon="el-icon-refresh"
              @click="serchReset()"
              >重置
            </el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8 operation-btn">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-menu"
              size="mini"
              @click="checkleAll"
              >查询所有</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              v-if="exportStatus == 'sort'"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleSortExport"
              v-hasPermi="['wm:balance:export']"
              >导出</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-printer"
              size="mini"
              @click="handlePrint"
              v-hasPermi="['wm:balance:print']"
              >打印</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-circle-check"
              size="mini"
              :disabled="queryParamsSort.sortId == ''"
              @click="handleCheck"
              v-hasPermi="['wm:balance:check']"
              >核验</el-button
            >
          </el-col>
        </el-row>
        <!-- 打印数据 -->
        <PrintPage :printData="printData" ref="startPrint" :title="printName" />
        <!-- 物料数据 -->
        <el-table
          v-loading="loading"
          :data="basicfileList"
          border
          :height="maxHeight"
        >
          <el-table-column type="index" width="60" align="center" label="序号">
          </el-table-column>
          <el-table-column
            label="物料编码"
            align="center"
            sortable
            prop="code"
            width="180"
          >
            <template slot-scope="scope">
              <span
                style="cursor: pointer"
                @click.stop="seeMaterial(scope.row)"
                >{{ scope.row.code }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="物料名称" align="center" prop="name" sortable>
            <template slot-scope="scope">
              <span
                style="cursor: pointer"
                @click.stop="seeMaterial(scope.row)"
                >{{ scope.row.name }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            label="型号规格"
            align="center"
            prop="attribute"
            width="120"
          />
          <el-table-column
            label="主计量"
            align="center"
            prop="unitName"
            width="80"
          />
          <el-table-column label="当前库存数量" align="center" width="130">
            <template slot-scope="scope">
              <div style="text-align: right">
                <span>{{ scope.row.quantity }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="锁定数量" align="center" width="130">
            <template slot-scope="scope">
              <div style="text-align: right">
                <span>{{ scope.row.lockQuantity }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="在途数量" align="center" width="130">
            <template slot-scope="scope">
              <div style="text-align: right">
                <span>{{ scope.row.wayQuantity }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="实际可用量" align="center" width="130">
            <template slot-scope="scope">
              <div style="text-align: right">
                <span>{{ scope.row.availableQuantity }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding"
            width="100"
          >
            <template slot-scope="scope">
              <div class="public-btn">
                <el-button
                  size="mini"
                  type="text"
                  class="basic-see"
                  @click.stop="handleDetailed(scope.row)"
                  v-hasPermi="['wm:balance:detail']"
                  >明细
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <!-- 分类查询分页信息 -->
    <pagination
      v-show="total >= 19 && pageStaus == 'sort'"
      :total="total"
      :page.sync="queryParamsSort.pageNum"
      :limit.sync="queryParamsSort.pageSize"
      @pagination="getSortMaterialList"
    />
    <!-- 分类查询分页信息 -->
    <pagination
      v-show="total >= 19 && pageStaus == 'wh'"
      :total="total"
      :page.sync="queryParamsWh.pageNum"
      :limit.sync="queryParamsWh.pageSize"
      @pagination="getWhMaterialList"
    />
    <!--汇总 -->
    <el-dialog title="物料汇总" :visible.sync="open" width="600px" v-if="open">
      <el-form
        ref="materialForm"
        :model="materialForm.items"
        label-width="80px"
        size="medium"
        :validate-on-rule-change="false"
        disabled
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="分类信息" prop="value">
              <el-cascader
                v-model="value"
                :options="sortTree"
                ref="classTree"
                :props="classProps"
                class="cas-input"
              >
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料编码">
              <el-input
                v-model="materialForm.items.code"
                :disabled="true"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="更新时间">
              <el-input
                v-model="materialForm.items.updateTime"
                class="updata-time"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料名称" prop="name">
              <el-input v-model="materialForm.items.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计量单位" prop="packingForm">
              <el-input v-model="materialForm.items.unitName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="型号规格" prop="attribute">
              <el-input v-model="materialForm.items.attribute"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 物料数量表单 -->
      <div class="from-mount">
        <p class="mount-title">总量</p>
        <el-form
          :model="materialForm.items"
          label-width="100px"
          size="medium"
          class="mount-form"
          disabled
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="当前库存数量" class="txt-right">
                <el-input
                  v-model="materialForm.items.quantity"
                  class="now-stock"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实际可用数量" class="txt-right">
                <el-input
                  v-model="materialForm.items.available"
                  class="now-actual"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划锁定数量">
                <el-input
                  v-model="materialForm.items.mp"
                  class="txt-right"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="销售锁定数量">
                <el-input
                  v-model="materialForm.items.om"
                  class="txt-right"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购在途数量">
                <el-input
                  v-model="materialForm.items.po"
                  class="txt-right"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="生产在途数量" class="txt-right">
                <el-input v-model="materialForm.items.prs"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="委外在途数量" class="txt-right">
                <el-input v-model="materialForm.items.pu"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div
        class="from-mount"
        v-for="(item, index) in materialForm.wm"
        :key="index"
      >
        <p class="mount-title">{{ item.whName }}</p>
        <el-form
          :model="materialMount"
          label-width="100px"
          size="medium"
          class="mount-form"
          disabled
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="当前库存数量" class="txt-right">
                <el-input v-model="item.quantity" class="now-stock"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实际可用数量" class="txt-right">
                <el-input
                  v-model="item.available"
                  class="now-actual"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划锁定数量">
                <el-input v-model="item.mp" class="txt-right"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="销售锁定数量">
                <el-input v-model="item.om" class="txt-right"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购在途数量">
                <el-input v-model="item.po" class="txt-right"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="生产在途数量" class="txt-right">
                <el-input v-model="item.prs"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="委外在途数量" class="txt-right">
                <el-input v-model="item.pu"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-dialog>
    <!-- 明细弹框 -->
    <el-dialog
      title="物料明细"
      class="detailed-box"
      :visible.sync="detailedStatus"
      width="70%"
      v-if="detailedStatus"
    >
      <el-table
        :data="detailedDtata"
        border
        v-loading="loading"
        :height="detailedHeight"
      >
        <el-table-column type="index" width="60" align="center" label="序号">
        </el-table-column>
        <el-table-column label="仓库" align="center" prop="name" width="80">
        </el-table-column>
        <el-table-column label="物料编码" align="center" prop="inv_code">
        </el-table-column>
        <el-table-column
          label="物料名称"
          align="center"
          prop="inv_name"
          width="200"
        >
        </el-table-column>
        <el-table-column
          label="型号规格"
          align="center"
          prop="inv_attribute"
          width="100"
        >
        </el-table-column>
        <el-table-column
          label="主计量"
          align="center"
          prop="unit_name"
          width="100"
        >
        </el-table-column>
        <el-table-column
          label="批号"
          align="center"
          prop="batch_number"
          width="150"
        >
        </el-table-column>
        <el-table-column label="属性" align="center">
          <template slot-scope="scope">
            <div>
              <span
                >{{ scope.row.f1 }}&nbsp;&nbsp;{{ scope.row.f2 }}&nbsp;&nbsp;{{
                  scope.row.f3
                }}&nbsp;&nbsp;{{ scope.row.f4 }}&nbsp;&nbsp;{{
                  scope.row.f5
                }}</span
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column label="入库数量" align="center">
          <template slot-scope="scope">
            <div style="text-align: right">
              <span>{{ scope.row.quantity }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="领用数量" align="center">
          <template slot-scope="scope">
            <div style="text-align: right">
              <span>{{ scope.row.wi_quantity }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="剩余数量" align="center">
          <template slot-scope="scope">
            <div style="text-align: right">
              <span>{{ scope.row.surplus }}</span>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import { listSort } from "../../api/sort"; //分类接口
import {
  listSortMaterial, //分类物料
  listWhMaterial, //仓库物料
  seeMaterial, //物料汇总
  listPacking, //计量单位
  exportSortMaterial, //导出分类物料
  exportWhMaterial, //导出仓库物料
  listWarehouses, //仓库列表
  detailedMaterial, //物料明细
} from "../../api/balance"; //物料接口
import { getTreeData, getEcho } from "../../utils/balance"; //js方法
import Tree from "../../components/Sort/tree"; //分类组件
import PrintPage from "../../components/Balance/print"; //打印组件
import print from "print-js"; //打印js
import { supParent } from "../../utils/sort.js"; //打印获取分类名称
import axios from "axios";
export default {
  name: "Balance", //现存量
  data() {
    return {
      // 遮罩层
      loading: true,
      //分类搜索名称
      searchName: "",
      // 批量删除按钮状态
      multiple: true,
      //是否显示分类操作按钮
      isOperation: true,
      //树形数据
      sortTree: [],
      //树形选中是否高亮
      isHeight: true,
      //物料数据最大高度
      maxHeight: null,
      //搜索参数
      searchForm: {
        searchName: "", //搜索物料名称
        searchCode: "", //搜索物料编码
      },
      //仓库选择
      optionswarehouse: [],
      selectwarehouse: "",
      // 料品查询参数
      queryParamsSort: {
        pageNum: 1,
        pageSize: 100,
        sortId: "",
        invName: "",
        invCode: "",
      },
      // 料品查询参数
      queryParamsWh: {
        pageNum: 1,
        pageSize: 100,
        whCode: "",
      },
      // 物料明细查询参数
      queryParamsDetailed: {
        whCode: "",
        invCode: "",
      },
      // 总条数
      total: 0,
      //小数位数
      decimal: "4",
      //分页显示方式 分类查询/仓库查询
      pageStaus: "",
      //导出状态
      exportStatus: "sort",
      // 料品数据
      basicfileList: [],
      // 新增/修改/编辑弹框状态
      open: false,
      //明细弹框状态
      detailedStatus: false,
      //明细数据
      detailedDtata: [],
      //明细框高度
      detailedHeight: null,
      //选择分类回显信息
      value: [],
      //表单禁用状态
      seeStatus: false,
      //分类选择配置
      classProps: {
        children: "children",
        label: "sortName",
        value: "sortCode",
        checkStrictly: true,
      },
      packingDate: [],
      // 计量单位
      packingForm: "",
      // 物料新增/修改信息表单
      materialForm: {
        items: {},
        wm: [],
      },
      // 核验地址
      effecUrl: process.env.VUE_APP_BASE_API + "//wm/balance/check/",

      //打印分类名称
      printName: "",
      //打印数据
      printData: [],
      //批量打印数据
      batchPrintData: [],
      //物料查看数量表单
      materialMount: {
        items: {},
        wm: [],
      },
    };
  },
  created() {
    //初始化分类数据
    this.getTreeList();
    //初始化物料数据
    this.getSortMaterialList();
    //初始化仓库列表
    this.getHouselList();
    this.exportStatus = "sort";
    //隐藏操作按钮
    this.isOperation = false;
  },
  methods: {
    //获取分类数据
    getTreeList() {
      (this.loading = true),
        listSort({
          feature: "",
        }).then((res) => {
          this.sortTree = getTreeData(res.data); //当children为0时，赋值undefined
          this.loading = false;
        });
    },

    // 获取分类物料数据
    getSortMaterialList() {
      listSortMaterial(this.queryParamsSort).then((res) => {
        this.pageStaus = "sort";
        let arrBasic = JSON.parse(JSON.stringify(res.rows));
        //数量格式化4位小说
        if (arrBasic.length > 0) {
          arrBasic.forEach((value) => {
            value.quantity = value.quantity.toFixed(this.decimal);
            value.lockQuantity = value.lockQuantity.toFixed(this.decimal);
            value.wayQuantity = value.wayQuantity.toFixed(this.decimal);
            value.availableQuantity = value.availableQuantity.toFixed(
              this.decimal
            );
          });
        }

        this.basicfileList = arrBasic;
        this.total = res.total;
        if (this.basicfileList.length >= 19) {
          //条数总数大于显示出现滚动条
          this.maxHeight = `${document.documentElement.clientHeight}` - 270;
        } else {
          this.maxHeight = "";
        }
      });
    },

    // 获取仓库查询物料数据
    getWhMaterialList() {
      listWhMaterial(this.queryParamsWh).then((res) => {
        this.pageStaus = "wh";
        this.decimal = "4";
        let arrBasic = JSON.parse(JSON.stringify(res.data.data.rows));
        this.basicfileList = JSON.parse(
          JSON.stringify(arrBasic)
            .replace(/invCode/g, "code")
            .replace(/invName/g, "name")
            .replace(/invAttribute/g, "attribute")
            .replace(/invSortId/g, "sortId")
        );
        this.total = res.data.data.total;
        if (this.basicfileList.length >= 19) {
          //条数总数大于显示出现滚动条
          this.maxHeight = `${document.documentElement.clientHeight}` - 270;
        } else {
          this.maxHeight = "";
        }
      });
    },

    // 核验物料
    handleCheck() {
      axios({
        methods: "get",
        url: this.effecUrl,
        params: {
          sortId: this.queryParamsSort.sortId,
        },
        headers: {
          Authorization: "Bearer " + getToken(),
        },
      }).then((res) => {
        this.$alert(res.data.msg, "核验结果", {
          dangerouslyUseHTMLString: true,
        });
      });
    },

    //搜索物料
    search() {
      if (
        this.searchForm.searchName == "" &&
        this.searchForm.searchCode == ""
      ) {
        this.msgError("物料编码或物料名称不能同时为空！");
      } else {
        this.queryParamsSort.invName = this.searchForm.searchName; //赋值物料名称
        this.queryParamsSort.invCode = this.searchForm.searchCode; //赋值物料编码
        this.queryParamsSort.sortId = ""; //避免当分类树点击时页面缓存的sortId导致搜索失败
        this.getSortMaterialList();
      }
    },

    // 仓库列表
    getHouselList() {
      listWarehouses().then((res) => {
        if (res.code == 200) {
          this.optionswarehouse = res.rows;
        }
      });
    },

    // 仓库选择
    warehouseChange(code) {
      this.queryParamsWh.whCode = code;
      this.queryParamsDetailed.whCode = code;
      this.exportStatus = "wh";
      this.isHeight = false; //关闭分类树高亮
      let wmObj = {};
      wmObj = this.optionswarehouse.find((item) => {
        return item.code == code;
      });
      this.printName = wmObj.name + "-";
      this.getWhMaterialList();
    },

    // 点击仓库下拉
    handleWarehouse() {
      this.getHouselList();
    },

    //获取计量单位数据
    getPacking() {
      return new Promise((resolve, reject) => {
        listPacking()
          .then((res) => {
            if (res.code == 200) {
              this.packingDate = res.rows;
              resolve();
            }
          })
          .catch((err) => {
            this.msgError("获取计量单位失败！");
          });
      });
    },

    //物料分类点击获取
    nodeClick(node) {
      this.selectwarehouse = "";
      this.queryParamsDetailed.whCode = "";
      // 获取上级分类名称
      const name = [];
      const getParentName = supParent(node[1], name).reverse(); //获取上级分类名称
      this.packingForm = node[0].unitCode; //获取默认计量单位
      if (this.packingForm !== "") {
        this.handlePacking(node[0].unitCode); //得到单位编码与名称字段
      }
      const parentName = getParentName.join(" / "); //拼接上级分类名称
      if (node[1].data.parentId == 0) {
        this.printName = node[1].data.sortName + "-"; //主类上级分类为自身
      } else {
        this.printName = parentName + " / " + node[1].data.sortName + "-"; //子类上级分类最终结果
      }
      this.undataAddSee(node[0].sortId).then(() => {
        this.isHeight = true; //打开分类树高亮
        this.exportStatus = "sort";
        this.queryParamsSort.sortId = node[0].sortId; //赋值sortId用于搜索
          this.queryParamsSort.invName = "";
          this.searchForm.searchName = ""; 
        this.queryParamsSort.invCode = "";
         this.searchForm.searchCode = "";
        this.getSortMaterialList(); //重新拉取数据
      });
    },

    //选择计量单位
    handlePacking(value) {
      if (this.packingDate.length > 0) {
        let obj = {};
        obj = this.packingDate.find((item) => {
          return item.code === value;
        });
        this.materialForm.items.unitCode = obj.code; //计量单位编码
        this.materialForm.items.unitName = obj.name; //计量单位名称
      }
    },

    // 查询所有
    checkleAll() {
      //清空搜索信息，避免干扰
      this.searchForm.searchName = "";
      this.searchForm.searchCode = "";
      this.queryParamsSort.sortId = "";
      this.queryParamsSort.invName = "";
      this.queryParamsSort.invCode = "";
      this.selectwarehouse = "";
      this.printName = "";
      this.isHeight = false; //关闭分类树高亮
      this.exportStatus = "sort";
      this.decimal = "4";
      this.getSortMaterialList();
    },

    //分类现存量导出
    handleSortExport() {
      const queryParams = this.queryParamsSort;
      this.$confirm("是否确认导出所选物料数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportSortMaterial(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },

    //仓库导出
    handleWhExport() {
      const queryParams = this.queryParamsWh;
      this.$confirm("是否确认导出所选物料数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportWhMaterial(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },

    // 打印
    handlePrint() {
      let number = 1;
      this.printData = this.basicfileList;
      this.printData.forEach((obj) => {
        obj.id = number++;
      });
      setTimeout(() => {
        this.$print(this.$refs.startPrint.$refs.print);
      }, 0);
    },

    // 分类选择回显结果
    handleChange(value) {
      value = value.join(""); //转换成字符串，用于传值后台
      this.materialForm.items.code = value;
      this.materialForm.items.sortId =
        this.$refs["classTree"].getCheckedNodes()[0].data.sortId; //赋值sortId
    },

    //汇总物料
    seeMaterial(row) {
      this.getPacking().then(() => {
        //确保已获取计量单位成功
        this.undataAddSee(row.sortId).then(() => {
          this.materialForm.wm = [];
          seeMaterial({
            invCode: row.code,
          }).then((res) => {
            if (res.code == 200) {
              let items = JSON.parse(JSON.stringify(res.data.items));
              items.mp = items.mp.toFixed(this.decimal);
              items.om = items.om.toFixed(this.decimal);
              items.po = items.po.toFixed(this.decimal);
              items.prs = items.prs.toFixed(this.decimal);
              items.quantity = items.quantity.toFixed(this.decimal);
              items.available = items.available.toFixed(this.decimal);
              items.pu = items.pu.toFixed(this.decimal);
              this.materialForm.items = items; //拷贝物料信息
              // 数量小数位格式化
              if (res.data.wm.length > 0) {
                let basicMount = JSON.parse(JSON.stringify(res.data.wm));
                console.log(basicMount);
                basicMount.forEach((obj) => {
                  obj.mp = obj.mp.toFixed(this.decimal);
                  obj.om = obj.om.toFixed(this.decimal);
                  obj.po = obj.po.toFixed(this.decimal);
                  obj.prs = obj.prs.toFixed(this.decimal);
                  obj.quantity = obj.quantity.toFixed(this.decimal);
                  obj.available = obj.available.toFixed(this.decimal);
                  obj.pu = obj.pu.toFixed(this.decimal);
                });
                this.materialForm.wm = basicMount;
                console.log(this.materialForm);
              }
              this.open = true;
              this.packingForm = row.unitCode;
            }
          });
        });
      });
    },

    //明细物料
    handleDetailed(row) {
      this.queryParamsDetailed.invCode = row.code;
      detailedMaterial({ invCode: row.code }).then((res) => {
        if (res.code == 200) {
          let list = JSON.parse(JSON.stringify(res.data));
          list.forEach((obj) => {
            obj.quantity = obj.quantity.toFixed(this.decimal);
            obj.surplus = obj.surplus.toFixed(this.decimal);
            obj.wi_quantity = obj.wi_quantity.toFixed(this.decimal);
          });
          this.detailedDtata = list;
          this.detailedHeight =
            `${document.documentElement.clientHeight}` - 400;
          this.detailedStatus = true;
        }
      });
    },
    // 新增/修改/查看公共获取分类回显

    // 新增/修改/查看公共获取分类回显
    undataAddSee(id) {
      return new Promise((resolve, reject) => {
        let parentArr = [], //用于储存父类分类信息
          childrenArr = []; ////用于储存子类分类信息
        getEcho(id, this.sortTree, parentArr, childrenArr).then((res) => {
          setTimeout(() => {
            let success = [];
            for (let i = 0; i < res.length; i++) {
              if (success.indexOf(res[i]) === -1) {
                success.push(res[i]);
              }
            }
            let getNode = JSON.parse(JSON.stringify(success)); //拷贝vuex信息，避免影响源数据
            getNode.forEach((v) => {
              if (v.ancestors.indexOf(",") > -1) {
                //是否是子分类
                v.ancestors = v.ancestors.split(",").length; //拼接数组长度，用于排序
              } else {
                v.ancestors = 1;
              }
            });
            getNode.sort((a, b) => {
              //排序得到正常的分类顺序，用于得到sortCode
              return a.ancestors - b.ancestors;
            });
            let getCode = [];
            getNode.forEach((code) => {
              getCode.push(code.sortCode);
              this.materialForm.sortId = code.sortId;
            });
            this.value = getCode; //对话框分类回显
            if (this.butChange == "1") {
              //状态为新增物料
              getCode = getCode.join(""); //转换成字符串，用于传值后台
              this.materialForm.code = getCode;
            }
          }, 0);
        });
        resolve();
      });
    },

    //搜索表单重置
    serchReset() {
      for (let key in this.searchForm) {
        this.searchForm[key] = "";
      }
    },
  },

  components: {
    Tree,
    PrintPage,
  },
};
</script>
<style lang="scss">
.balance-box {
  .el-tree--highlight-current
    .el-tree-node.is-current
    > .el-tree-node__content {
    color: #1890ff;
  }

  .height-tree {
    height: calc(100vh - 220px);
  }

  .el-select {
    input {
      line-height: 28px;
      height: 28px;
      width: 150px;
    }
  }

  .txt-right {
    input {
      text-align: right;
    }
  }

  .el-dialog__body {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
  }

  .detailed-box {
    .el-dialog__body {
      padding-bottom: 30px;
    }
  }

  .mount-title {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    border-bottom: 1px solid #dfe6ec;
    padding-bottom: 15px;
    margin-bottom: 15px;
  }

  .el-input--medium .el-input__icon {
    line-height: 28px;
  }

  .operation-btn {
    .is-disabled {
      span {
        font-weight: 700;
      }
    }
  }

  .el-table--medium th,
  .el-table--medium td {
    overflow: inherit;
  }

  .el-table th > .cell {
    overflow: inherit;
    position: relative;
  }

  .caret-wrapper {
    position: absolute;
    right: 64px;
    top: -5px;
    display: none;
  }

  .el-button--info.is-plain.is-disabled {
    color: #adaeaf;
  }

  .cas-input input {
    color: #1890ff !important;
  }

  .keep-status {
    margin-top: 15px;
  }

  .updata-time {
    input {
      border: none;
    }
  }

  .el-cascader .el-input .el-input__inner {
    color: #1890ff;
  }

  .el-input--suffix input {
    color: #606266;
  }

  .el-cascader--medium {
    width: 100%;
  }

  .has-gutter th {
    text-align: center;
    overflow: inherit;
  }

  .el-dialog__body {
    padding-right: 20px;
    padding-bottom: 20px;
  }

  .now-stock {
    input {
      color: #1890ff !important;
    }
  }

  .now-actual input {
    color: #13ce66 !important;
  }

  .el-input.is-disabled .el-input__inner {
    color: #333;
  }

  .el-form-item--medium .el-form-item__content {
    margin-right: 10px;
  }

  .cell {
    padding-right: 14px !important;
    padding-left: 14px !important;

    .basic-delete {
      color: #f56c6c;
    }

    .basic-see {
      color: #67c23a;
    }

    button:hover i {
      font-weight: 700;
    }

    button:hover span {
      font-weight: 700;
    }
  }

  .from-mount {
    padding: 15px;
    box-shadow: 1px 1px 10px 1px #eee;
    border-radius: 5px;
    padding-bottom: 10px;
    margin: 10px 10px 0px 10px;

    h3 {
      font-weight: normal;
      font-size: 15px;
      margin-top: 0;
      text-align: center;
      color: #1890ff;
    }
  }

  .foot-bot {
    text-align: inherit !important;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .foot-star {
      color: #1682e6;

      label {
        font-weight: normal;
        font-size: 12px;
      }
    }
  }
}
</style>
